#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <dirent.h>

/*
 * Traverse Directory 
 */

int main(int argc, char* argv[]) {
	DIR  *dp;
	struct dirent *dirp;

	if (argc != 2) {
		printf("usage: ls directory\n");
		return -1;
	}

	if ((dp=opendir(argv[1])) == NULL) {		
		printf("can't open %s: %s\n",argv[1],strerror(errno));
		return -2;
	}

	while ((dirp=readdir(dp)) != NULL)
		printf("%s\n",dirp->d_name);

	closedir(dp);
	return 0;
}
